-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Maska989/TestStrStrPbrkTok #207
Conversation
8854cd3
to
ed22a9c
Compare
a58b7f3
to
480ecf8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just took a quick look, this is not a full review
480ecf8
to
ea1cdb6
Compare
f2b72a1
to
91ac620
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's improve these tests a little bit.
c5c801d
to
0122b8c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just took a quick look
1bb2699
to
3d3602b
Compare
|
||
memcpy(str2, str1, sizeof(str1)); | ||
|
||
TEST_ASSERT_EQUAL_PTR(str1, (token = strtok_r(str1, separators, &restState1))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why there are 2 variables called restState?
Please assert their values after call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those variables are restrictions for strtok_r to do thread-safe tokenization and to don't mix up tokenizations between two elements similar to themselves. Asserting this value is pointless because it is possible to assert this as not null, but we discard this option using the next tokenization without a mixup.
} | ||
|
||
|
||
TEST(string_pbrk, basic) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can certainly add more cases to cover this funciton. First example would be strbrk("abc", "") For example:
- passing bytes in the
s2
in various order, so strpbrk("abcde", "dce") - passing more bytes (than available in
s1
) ins2
, so sth like: strpbrk("abcde", "cdefgh") - big buffers
- a few same bytes in s2
- maybe some other cases
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried different approaches in those cases, I will wait for a response about them.
30c419e
to
281fa94
Compare
libc/string/string_tokpbrkstr.c
Outdated
TEST_ASSERT_EQUAL_PTR(str, strtok(str, empty)); | ||
TEST_ASSERT_EQUAL_PTR(NULL, strtok(NULL, empty)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove those local variables. As I mentioned before empty and "" are bot han empty string, so we can use only "".
TEST_ASSERT_EQUAL_PTR(str, strtok(str, empty)); | |
TEST_ASSERT_EQUAL_PTR(NULL, strtok(NULL, empty)); | |
TEST_ASSERT_EQUAL_PTR(str, strtok("abc", "")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, ok there is restrict
in the declaration. Using "\0" seems to be fine in this case.
libc/string/string_tokpbrkstr.c
Outdated
} | ||
|
||
|
||
TEST(string_tok_r, restriction) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't quite understand, first call puts a NULL pointer in asciiStr[2], so each of next calls will return only "1" as a token, I don't see a purpose of asserting it 255 times.
I suppose you wanted to test mainly the rest there, which in fact is the same for all iterations (I don't see why only two of the last rests have to be equal)
} | ||
|
||
free(extAsciiStr); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also create a case, where the separator string contains the same character a few times, same with str
, it could contain the same characters multiple times. There is no big
case, we can do it at once in such one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
create a case, where the separator string contains the same character a few times
Where is such case? I can't see it for strtok()
function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those cases are checked in multi_call
in strtok and strtok_r
f5bb7ab
to
ca1d9be
Compare
} | ||
|
||
free(extAsciiStr); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
create a case, where the separator string contains the same character a few times
Where is such case? I can't see it for strtok()
function.
485105b
to
3ee09c5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not so much left to change :)
3ee09c5
to
550dcde
Compare
550dcde
to
9b20059
Compare
9b20059
to
2578f3d
Compare
Added
function tests.
JIRA: CI-234
Description
Motivation and Context
Types of changes
How Has This Been Tested?
Checklist:
Special treatment